package com.tz.fdz_jiance.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tz.fdz_jiance.domain.Log;
import com.tz.fdz_jiance.mapper.LogMapper;
import com.tz.fdz_jiance.utils.ResponseUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController
public class DeviceController {

    @Autowired
    LogMapper logMapper;

    @PostMapping("/getdeviceslist")
    @CrossOrigin(origins = "*",maxAge = 3600)
    public HashMap<String, Object> getdeviceslist(@RequestBody JSONObject jsonparm, HttpServletRequest request, HttpSession session) {

        Page<Log> page = new Page<>(1, 10);
        QueryWrapper<Log> logQueryWrapper = new QueryWrapper<>();
        logQueryWrapper.orderByDesc("createtime");
        IPage<Log> logs = logMapper.selectPage(page , logQueryWrapper);
        return ResponseUtils.success(logs.getRecords().get(0));
    }

}
